using System.Text;
using LuckyLang.AST.Statement;
using sly.parser.generator;

namespace LuckyLang;

public class Interpreter
{
    private string ThePath { get; set; }

    public Interpreter(string path) => ThePath = path;
    public string FileToString() => File.ReadAllText(ThePath,Encoding.UTF8);
    public void Using()
    {
        ParserBuilder<Lexer, AST.AST> Parser = new (); //Token Lexer
        LuckyLang.Parser              parser = new Parser();
        var parserBuilder = Parser.BuildParser(parser,
                                               ParserType.EBNF_LL_RECURSIVE_DESCENT, "root");
        var buildResult = parserBuilder.Result;

        var r   = buildResult.Parse(FileToString());
        var RUN = r.Result;//code (Parser,Lexer) => AST => BlockStatement
        if (r.Errors !=null && r.Errors.Any())
            r.Errors.ForEach(x => Console.WriteLine(x.ErrorMessage));
        else
        {
            VariateManager Manager = new VariateManager();
            var            run     = RUN as Statement;
            Console.WriteLine(run);
            run.Run(ref Manager);
            Console.WriteLine(Manager);
        }
    }
}